package com.gy.boot.common.util;

import java.util.ArrayList;
import java.util.List;

public class NumberTool {

    public static Integer getInteger(Object obj) {
        if (obj == null) {
            return null;
        }
        return getInteger(obj.toString());
    }

    public static Integer getInteger(String str) {
        try {
            return Integer.parseInt(str);
        } catch (Exception e) {
            return null;
        }
    }

    public static Long getLong(Object obj) {
        if (obj == null) {
            return null;
        }
        return getLong(obj.toString());
    }

    public static Long getLong(String str) {
        try {
            return Long.parseLong(str);
        } catch (Exception e) {
            return null;
        }
    }

    public static Double getDouble(Object obj) {
        if (obj == null) {
            return null;
        }
        return getDouble(obj.toString());
    }

    public static Double getDouble(String str) {
        try {
            return Double.parseDouble(str);
        } catch (Exception e) {
            return null;
        }
    }


    public static List<int[]> listSubIndexArr(int maxSize, int listSize) {
        List<int[]> listArr = new ArrayList<>();
        int endI = 0;
        for (int i = maxSize; i <= listSize; i=i+maxSize) {
            endI = i;
            int startIndex = i - maxSize;
            listArr.add(new int[]{startIndex, endI});
        }
        if (endI != listSize) {
            listArr.add(new int[]{endI, listSize});
        }
        return listArr;
    }

}
